﻿using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ERP.infratrctrue
{
    // 修改这里：将SimpleClient<T>正确地加入继承列表
    public class BaseRepository<T> : SimpleClient<T>,IBaseRepository<T> where T : class,new ()
    {

       public BaseRepository(ISqlSugarClient   sql)
        {
            Sql = sql;
        }

        public ISqlSugarClient Sql { get; }

        public async Task<int> Add(T entity)
        {
          return await Sql.Insertable(entity).ExecuteCommandAsync();
        }

        public async Task<int> AddRange(List<T> values)
        {
            return await Sql.Insertable(values).ExecuteCommandAsync();
        }

        public List<T> GetAll()
        {
            return Sql.Queryable<T>().ToList();
        }

        public async Task<int> Update(T entity)
        {
            return await Sql.Updateable(entity).ExecuteCommandAsync();
        }

        public async Task<int> UpdateRange(List<T> values)
        {
            return await Sql.Updateable(values).ExecuteCommandAsync();
        }
    }
}
